import request from './request'
import type {
  BaseRes,
  CaptchaRes,
  LoginParams,
  LoginRes,
  UserInfo,
  UserMenuListRes,
  UserListParams,
  UserListRes,
  CreateUserParams,
  UpdateUserParams,
  RoleListRes,
  PermissionRes
} from '../types/services'

// 获取验证码
export const getCaptchaApi = () => {
  return request.get<BaseRes<CaptchaRes>>('/login/captcha')
}
// 登录接口
export const loginApi = (params: LoginParams) => {
  return request.post<BaseRes<LoginRes>>('/login', params)
}

// 退出登录接口
export const logoutApi = () => {
  return request.post<BaseRes<LoginRes>>('/user/logout')
}

// 个人信息
export const getUserInfoApi = () => {
  return request.get<BaseRes<UserInfo>>('/user/info')
}
// 当前用户可访问的菜单
export const getUserMenuListApi = () => {
  return request.get<BaseRes<UserMenuListRes>>('/user/menulist')
}

// 用户列表接口
export const getUserListApi = (params: UserListParams) => {
  return request.get<BaseRes<UserListRes>>('/user/list', {
    params
  })
}
// 新增用户
export const createUserApi = (params: CreateUserParams) => {
  return request.post<BaseRes>('/user/create', params)
}
// 更新用户
export const updateUserApi = (params: UpdateUserParams) => {
  return request.post<BaseRes>('/user/update', params)
}

// 角色列表
export const getRoleListApi = () => {
  return request.get<BaseRes<RoleListRes>>('/role/list')
}

// 权限列表
export const getPermissionListApi = () => {
  return request.get<BaseRes<PermissionRes>>('/permission/list')
}